package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 获取所有护理计划
     *
     * @return
     */
    @ApiOperation("获取所有护理计划")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan() {
        List<NursingPlanVo> nursingPlanvoList = nursingPlanService.getAllNursingPlan();
        return success(nursingPlanvoList);
    }

    /**
     * 新增护理计划
     *
     * @param nursingPlanDto
     * @return
     */
    @ApiOperation("新增护理计划")
    @PostMapping
    public ResponseResult addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return success();
    }

    /**
     * 分页查询
     *
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/search")
    public ResponseResult page(String name, Integer pageNum, Integer pageSize, Integer status) {
        log.info("name:{},page:{},pageSize:{},status:{}", name, pageNum, pageSize, status);
        PageResponse pageResponse = nursingPlanService.page(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    /**
     * 根据id查询护理计划
     * @param id
     * @return
     */
    @ApiOperation("根据id查询")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> searchByName(@PathVariable Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.searchById(id);
        return success(nursingPlanVo);
    }

    /**
     * 根据id删除护理计划
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        nursingPlanService.delete(id);
        return success();
    }

    /**
     * 根据id修改
     * @param nursingPlanDto
     * @return
     */
    @PutMapping("/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult OpenOrClose(@PathVariable Long id, @PathVariable Integer status){
        nursingPlanService.enableOrDisable(id,status);
        return success();
    }
}
